// src/router/index.ts
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
// 静态路由
const Login = () => import("@/views/login/index.vue");
const Index = () => import("@/views/layout/index.vue");
const Error404 = () => import("@/views/error/404.vue");
const Error401 = () => import("@/views/error/401.vue");
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    component: Login,
    meta: { hidden: true },
  },
  {
    path: "/index",
    component: Index,
    meta: { hidden: true },
  },
  {
    path: "/:pathMatch(.*)*",
    component: Error404,
    meta: { hidden: true },
  },
  {
    path: "/401",
    component: Error401,
    meta: { hidden: true },
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
  location.reload();
}

export default router;
